package productions;

import exceptions.ParserException;
import lexico.ErrorTable;
import lexico.SymbolTable;
import lexico.TokenClass;

/**
 * @author heekinho
 */
public class ArgsProduction extends AbstractProductionRule {
    /* Muitos dos métodos irão precisar de algo assim: */

    private static ArgsProduction instance = new ArgsProduction();

    public static ArgsProduction getInstance() {
        return instance;
    }

    /**
     * Regra: params : valor (',' valor)*;
     * @return
     * @throws ParserException
     */
    @Override
    public boolean analyze(SymbolTable st, ErrorTable et) throws ParserException {
        if (!DclrVarProduction.getInstance().analyze(st, et)) {
            return false;
        }

        while (basicParse(st, TokenClass.DELIMITER_COMMA)) {
            if (!DclrVarProduction.getInstance().analyze(st, et)) {
                return skipUntilSynchronize(st, et, "Erro na passagem de parametros");
            }
        }

        return true;
    }

    @Override
    protected void populateFirst() {

        //from declrvar.first
        first.add(TokenClass.IDENTIFIER);
        first.add(TokenClass.KEYWORD_INTEIRO);
        first.add(TokenClass.KEYWORD_REAL);
        first.add(TokenClass.KEYWORD_LOGICO);
        first.add(TokenClass.KEYWORD_CARACTERE);
        first.add(TokenClass.KEYWORD_STRING);
    }

    @Override
    protected void populateFollow() {
        follow.add(TokenClass.DELIMITER_CLOSING_PARENTHESIS);
    }

    
}
